#!/bin/bash

# Mini-gRPC HelloWorld 演示运行脚本

echo "🚀 Mini-gRPC HelloWorld 演示"
echo "================================"

# 检查是否已编译
if [ ! -d "mini-grpc-examples/target/classes" ]; then
    echo "📦 正在编译项目..."
    mvn clean compile -DskipTests
    if [ $? -ne 0 ]; then
        echo "❌ 编译失败，请检查错误信息"
        exit 1
    fi
    echo "✅ 编译完成"
fi

# 设置类路径
CLASSPATH="mini-grpc-core/target/classes:mini-grpc-examples/target/classes"

echo ""
echo "选择运行模式："
echo "1. 完整演示 (推荐) - 自动启动服务端和客户端"
echo "2. 仅启动服务端"
echo "3. 仅启动客户端"
echo ""

read -p "请选择 (1-3): " choice

case $choice in
    1)
        echo "🎯 启动完整演示..."
        java -cp "$CLASSPATH" com.mini.grpc.examples.helloworld.HelloWorldDemo
        ;;
    2)
        echo "📡 启动服务端..."
        java -cp "$CLASSPATH" com.mini.grpc.examples.helloworld.HelloWorldServer
        ;;
    3)
        echo "🔗 启动客户端..."
        java -cp "$CLASSPATH" com.mini.grpc.examples.helloworld.HelloWorldClient
        ;;
    *)
        echo "❌ 无效选择"
        exit 1
        ;;
esac 